package tlcn.business;

import java.util.ArrayList;
import tlcn.app.R;
import tlcn.data.Dish;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListDishesAdapter extends ArrayAdapter<Dish> {

	ArrayList<Dish> listDishes;
	Context context;
	int resourceID;
	Intent intent;
	public ListDishesAdapter(Context context, int resourceID, ArrayList<Dish> objects,Intent intent) {
		super(context, resourceID, objects);
		this.context=context;
		this.resourceID=resourceID;
		this.intent=intent;
		listDishes=objects;
	}
	@Override
	public View getView(final int position, View v, ViewGroup parent) {
		v= View.inflate(context, resourceID, null);
		ImageView imgDish= (ImageView) v.findViewById(R.id.imgDish);
		imgDish.setImageBitmap(listDishes.get(position).getImg());
		TextView txtDishName= (TextView) v.findViewById(R.id.txtDishName);
		txtDishName.setText(listDishes.get(position).getDishName());
		v.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				intent.putExtra("DishID", listDishes.get(position).getDishID());
				intent.putExtra("guide", listDishes.get(position).getGuide());
				intent.putExtra("linkVideo", listDishes.get(position).getVideo());
				intent.putExtra("name", listDishes.get(position).getDishName());
				context.startActivity(intent);
			}
		});
		return v;
	}

}
